package com.ruix.app.model;

import android.graphics.Color;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/5/9.
 */

public class Course {

    private String name;
    private String color;
    private ArrayList<Lesson> lessons;


    public Course parse(JSONObject object){
        if (object != null){
            setName(object.optString("name",""));
            setColor(object.optString("color",""));
            JSONArray lessonsArray = object.optJSONArray("lessons");
            if (lessonsArray != null &&lessonsArray.length() > 0){
                lessons = new ArrayList<>();
                for (int i = 0; i < lessonsArray.length(); i++) {
                    Lesson lesson = new Lesson().parse(lessonsArray.optJSONObject(i));
                    lessons.add(lesson);
                }
            }
        }

        return this;
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public ArrayList<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(ArrayList<Lesson> lessons) {
        this.lessons = lessons;
    }

    public int lessonsSize(){
        if (lessons != null){
            return lessons.size();
        }
        return 0;
    }


    @Override
    public String toString() {
        return "Course{" +
                "name='" + name + '\'' +
                ", color='" + color + '\'' +
                ", lessons=" + lessons +
                '}';
    }

    public boolean isLastLesson(int position){
        if (lessons != null && position == lessons.size() -1){
            return true;
        }
        return false;
    }
}
